package com.crowntit.types.design.framework.link.model2.chain;

import com.crowntit.types.design.framework.link.model1.ILogicLink;
import com.crowntit.types.design.framework.link.model2.handler.ILogicHandler;

public class BusinessLinkedLink<T, D, R> extends LinkedList<ILogicHandler<T, D, R>> implements ILogicHandler<T, D, R> {

    public BusinessLinkedLink(String name) {
        super(name);
    }

    @Override
    public R apply(T requestParam, D dynamicContext) throws Exception {
        Node<ILogicHandler<T, D, R>> target = this.first;
        do {
            ILogicHandler<T, D, R> item = target.item;
            R apply = item.apply(requestParam, dynamicContext);
            if (apply != null)
                return apply;

            target = target.next;
        } while (target != null);
        return null;
    }
}
